define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                 store_id:0,
                 editData:{},
                 logoString:[]
                };
            },
            el: '#pageUserInfo',
            created: function() {
                this.fetchData();
            },
              mounted: function() {
                    
                    if (this.mounted == 1) {
                        return;
                    }
                    
                this.mounted = 1;
            },

            methods: {
                fetchData: function() {
                    var _this = this;

                    this.getData();
                   
                   
                },
                bindphone:function(){
                   app.bindPhone();
                },
                getData:function(){
                    var that = this ;
                    that.loading = 1;
                     
                    app.get("api/user/info", {
                       
                    }, function (res) {
                      that.loading = 0;
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      that.editData = res.data; 
                      if(that.editData.avatarUrl){
                          that.logoString = JSON.stringify([{name:'avatarUrl',file_url:that.editData.avatarUrl}]);
                       }
                       that.$nextTick(function(){
                         app.upload($("#storeLogo"));
                       });
                    });
                },
                cancel:function(){
                 window.history.back();
                },
                save:function(id){
                   var that = this;
                   if(that.loading==1){
                      return ;
                   }
                   this.loading=1;
                   var post ={};
                  $("#formNewBook").find("input").each(function(i,input){
                     post[$(input).attr('name')] = $(input).val();
                  });
                  
                  app.post("apiv2/user/updateUser",post,function(res){
                        that.loading=0;
                            if(res.code!=200){
                               app.alert(res.msg);
                               return ;
                            }
                           app.alert('保存成功');
                          window.history.back();
              
                    });
                }
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
